<div class="content-section introduction">
    <div class="feature-intro">
        <h1>Checkbox</h1>
        <p>Checkbox is an extension to standard checkbox element with theming.</p>
    </div>
    <app-inputStyleSwitch></app-inputStyleSwitch>
</div>

<div class="content-section implementation">
    <div class="card">
        <h5>Basic</h5>
        <div class="p-field-checkbox">
            <p-checkbox [(ngModel)]="checked" binary="true" inputId="binary"></p-checkbox>
            <label for="binary">{{checked}}</label>
        </div>
        <h5>Multiple</h5>
        <div class="p-field-checkbox">
            <p-checkbox name="group1" value="New York" [(ngModel)]="selectedCities" inputId="ny"></p-checkbox>
            <label for="ny">New York</label>
        </div>
        <div class="p-field-checkbox">
            <p-checkbox name="group1" value="San Francisco" [(ngModel)]="selectedCities" inputId="sf"></p-checkbox>
            <label for="sf">San Francisco</label>
        </div>
        <div class="p-field-checkbox">
            <p-checkbox name="group1" value="Los Angeles" [(ngModel)]="selectedCities" inputId="la"></p-checkbox>
            <label for="la">Los Angeles</label>
        </div>
        <div class="p-field-checkbox">
            <p-checkbox name="group1" value="Chicago" [(ngModel)]="selectedCities" inputId="ch"></p-checkbox>
            <label for="ch">Chicago</label>
        </div>

        <h5>Dynamic Values, Preselection, Value Binding and Disabled Option</h5>
        <div *ngFor="let category of categories" class="p-field-checkbox">
            <p-checkbox name="group2" value="category" [value]="category"  [(ngModel)]="selectedCategories" [inputId]="category.key" [disabled]="category.key === 'R'"></p-checkbox>
            <label [for]="category.key">{{category.name}}</label>
        </div>
    </div>
</div>

<div class="content-section documentation">
    <p-tabView>
        <p-tabPanel header="Documentation">
            <h5>Import</h5>
<app-code lang="typescript" ngNonBindable ngPreserveWhitespaces>
import &#123;CheckboxModule&#125; from 'primeng/checkbox';
</app-code>

            <h5>Getting Started</h5>
            <p>Checkbox can either be used in multiple selection with other checkboxes or as a single checkbox to provide a boolean value.</p>
            
            <h4>Multiple Values</h4>
            <p>Multiple mode is enabled by default, ngModel property refers to an array to bind the selected values.</p>
<app-code lang="markup" ngNonBindable ngPreserveWhitespaces>
&lt;p-checkbox name="groupname" value="val1" [(ngModel)]="selectedValues"&gt;&lt;/p-checkbox&gt;
&lt;p-checkbox name="groupname" value="val2" [(ngModel)]="selectedValues"&gt;&lt;/p-checkbox&gt;
</app-code>

<app-code lang="typescript" ngNonBindable ngPreserveWhitespaces>
export class ModelComponent &#123;

    selectedValues: string[] = [];

&#125;
</app-code>

            <p>As ngModel is two-way binding enabled, prepopulating the model array with values is enough to display the related
            checkboxes as checked by default.</p>
<app-code lang="typescript" ngNonBindable ngPreserveWhitespaces>
export class ModelComponent &#123;

    selectedValues: string[] = ['val1','val2'];

&#125;
</app-code>

        <h4>Label</h4>
        <p>The label attribute provides a label text for the checkbox. This label is also clickable and toggles the checked state.</p>
<app-code lang="markup" ngNonBindable ngPreserveWhitespaces>
&lt;p-checkbox name="groupname" value="val1" label="Value 1" [(ngModel)]="selectedValues"&gt;&lt;/p-checkbox&gt;
&lt;p-checkbox name="groupname" value="val2" label="Value 2" [(ngModel)]="selectedValues"&gt;&lt;/p-checkbox&gt;
</app-code>

        <h4>Boolean Value</h4>
        <p>A single boolean value can be bound using the ngModel property as well by enabling the binary option.</p>
<app-code lang="typescript" ngNonBindable ngPreserveWhitespaces>
export class ModelComponent &#123;

    value: boolean;

&#125;
</app-code>

<app-code lang="markup" ngNonBindable ngPreserveWhitespaces>
&lt;p-checkbox [(ngModel)]="value" [binary]="true"&gt;&lt;/p-checkbox&gt;
</app-code>

        <h5>Model Driven Forms</h5>
        <p>Checkbox can be used in a model driven form as well. In this case, due to an <a href="https://github.com/angular/angular/issues/17685">issue</a> in Angular bind the formControl instance 
            instead of using formControlName.</p>
<app-code lang="markup" ngNonBindable ngPreserveWhitespaces>
&lt;!-- Wrong --&gt;
&lt;p-checkbox formControlName="cities"&gt;&lt;/p-checkbox&gt;

&lt;!-- Correct --&gt;
&lt;p-checkbox [formControl]="myFormGroup.controls['cities']"&gt;&lt;/p-checkbox&gt;
</app-code>

            <h5>Properties</h5>
            <div class="doc-tablewrapper">
                <table class="doc-table">
                    <thead>
                        <tr>
                            <th>Name</th>
                            <th>Type</th>
                            <th>Default</th>
                            <th>Description</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr>
                            <td>name</td>
                            <td>string</td>
                            <td>null</td>
                            <td>Name of the checkbox group.</td>
                        </tr>
                        <tr>
                            <td>value</td>
                            <td>any</td>
                            <td>null</td>
                            <td>Value of the checkbox.</td>
                        </tr>
                        <tr>
                            <td>label</td>
                            <td>string</td>
                            <td>null</td>
                            <td>Label of the checkbox.</td>
                        </tr>
                        <tr>
                            <td>disabled</td>
                            <td>boolean</td>
                            <td>false</td>
                            <td>When present, it specifies that the element should be disabled.</td>
                        </tr>
                        <tr>
                            <td>binary</td>
                            <td>boolean</td>
                            <td>false</td>
                            <td>Allows to select a boolean value instead of multiple values.</td>
                        </tr>
                        <tr>
                            <td>tabindex</td>
                            <td>number</td>
                            <td>null</td>
                            <td>Index of the element in tabbing order.</td>
                        </tr>
                        <tr>
                            <td>inputId</td>
                            <td>string</td>
                            <td>null</td>
                            <td>Identifier of the focus input to match a label defined for the component.</td>
                        </tr>
                        <tr>
                            <td>ariaLabelledBy</td>
                            <td>string</td>
                            <td>null</td>
                            <td>Establishes relationships between the component and label(s) where its value should be one or more element IDs.</td>
                        </tr>
                        <tr>
                            <td>style</td>
                            <td>object</td>
                            <td>null</td>
                            <td>Inline style of the component.</td>
                        </tr>
                        <tr>
                            <td>styleClass</td>
                            <td>string</td>
                            <td>null</td>
                            <td>Style class of the component.</td>
                        </tr>
                        <tr>
                            <td>labelStyleClass</td>
                            <td>string</td>
                            <td>null</td>
                            <td>Style class of the label.</td>
                        </tr>
                        <tr>
                            <td>checkboxIcon</td>
                            <td>string</td>
                            <td>pi pi-check</td>
                            <td>Icon class of the checkbox icon.</td>
                        </tr>
                        <tr>
                            <td>readonly</td>
                            <td>boolean</td>
                            <td>false</td>
                            <td>When present, it specifies that the component cannot be edited.</td>
                        </tr>
                        <tr>
                            <td>required</td>
                            <td>boolean</td>
                            <td>false</td>
                            <td>When present, it specifies that checkbox must be checked before submitting the form.</td>
                        </tr>
                    </tbody>
                </table>
            </div>

            <h5>Events</h5>
            <div class="doc-tablewrapper">
                <table class="doc-table">
                    <thead>
                        <tr>
                            <th>Name</th>
                            <th>Parameters</th>
                            <th>Description</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr>
                            <td>onChange</td>
                            <td>
                                checked: Boolean value to represent new state of checkbox.
                                originalEvent: Browser event
                            </td>
                            <td>Callback to invoke on checkbox click.</td>
                        </tr>
                    </tbody>
                </table>
            </div>

            <h5>Methods</h5>
            <div class="doc-tablewrapper">
                <table class="doc-table">
                    <thead>
                        <tr>
                            <th>Name</th>
                            <th>Parameters</th>
                            <th>Description</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr>
                            <td>focus</td>
                            <td>-</td>
                            <td>Applies focus.</td>
                        </tr>
                    </tbody>
                </table>
            </div>

            <h5>Styling</h5>
            <p>Following is the list of structural style classes, for theming classes visit <a href="#" [routerLink]="['/theming']">theming page</a>.</p>
            <div class="doc-tablewrapper">
                <table class="doc-table">
                    <thead>
                        <tr>
                            <th>Name</th>
                            <th>Element</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr>
                            <td>p-chkbox</td>
                            <td>Container element</td>
                        </tr>
                        <tr>
                            <td>p-chkbox-box</td>
                            <td>Container of icon.</td>
                        </tr>
                        <tr>
                            <td>p-chkbox-icon</td>
                            <td>Icon element.</td>
                        </tr>
                        <tr>
                            <td>p-chkbox-label</td>
                            <td>Label element.</td>
                        </tr>
                        <tr>
                            <td>p-label-active</td>
                            <td>Label element of a checked state.</td>
                        </tr>
                        <tr>
                            <td>p-label-focus</td>
                            <td>Label element of a focused state.</td>
                        </tr>
                        <tr>
                            <td>p-label-disabled</td>
                            <td>Label element of a disabled state.</td>
                        </tr>
                    </tbody>
                </table>
            </div>

            <h5>Dependencies</h5>
            <p>None.</p>
        </p-tabPanel>
        <p-tabPanel header="Source">
            <a href="https://github.com/primefaces/primeng/tree/master/src/app/showcase/components/checkbox" class="btn-viewsource" target="_blank">
                <span>View on GitHub</span>
            </a>
            <a href="https://stackblitz.com/edit/primeng-checkbox-demo" class="btn-viewsource" style="margin-left: .5em;" target="_blank">
                <span>Edit in StackBlitz</span>
            </a>
<app-code lang="markup" ngNonBindable ngPreserveWhitespaces>
&lt;h5&gt;Basic&lt;/h5&gt;
&lt;div class="p-field-checkbox"&gt;
    &lt;p-checkbox [(ngModel)]="checked" binary="true" inputId="binary"&gt;&lt;/p-checkbox&gt;
    &lt;label for="binary"&gt;&#123;&#123;checked&#125;&#125;&lt;/label&gt;
&lt;/div&gt;
&lt;h5&gt;Multiple&lt;/h5&gt;
&lt;div class="p-field-checkbox"&gt;
    &lt;p-checkbox name="group1" value="New York" [(ngModel)]="selectedCities" inputId="ny"&gt;&lt;/p-checkbox&gt;
    &lt;label for="ny"&gt;New York&lt;/label&gt;
&lt;/div&gt;
&lt;div class="p-field-checkbox"&gt;
    &lt;p-checkbox name="group1" value="San Francisco" [(ngModel)]="selectedCities" inputId="sf"&gt;&lt;/p-checkbox&gt;
    &lt;label for="sf"&gt;San Francisco&lt;/label&gt;
&lt;/div&gt;
&lt;div class="p-field-checkbox"&gt;
    &lt;p-checkbox name="group1" value="Los Angeles" [(ngModel)]="selectedCities" inputId="la"&gt;&lt;/p-checkbox&gt;
    &lt;label for="la"&gt;Los Angeles&lt;/label&gt;
&lt;/div&gt;
&lt;div class="p-field-checkbox"&gt;
    &lt;p-checkbox name="group1" value="Chicago" [(ngModel)]="selectedCities" inputId="ch"&gt;&lt;/p-checkbox&gt;
    &lt;label for="ch"&gt;Chicago&lt;/label&gt;
&lt;/div&gt;

&lt;h5&gt;Dynamic Values, Preselection, Value Binding and Disabled Option&lt;/h5&gt;
&lt;div *ngFor="let category of categories" class="p-field-checkbox"&gt;
    &lt;p-checkbox name="group2" value="category" [value]="category"  [(ngModel)]="selectedCategories" [inputId]="category.key" [disabled]="category.key === 'R'"&gt;&lt;/p-checkbox&gt;
    &lt;label [for]="category.key"&gt;&#123;&#123;category.name&#125;&#125;&lt;/label&gt;
&lt;/div&gt;
</app-code>

<app-code lang="typescript" ngNonBindable ngPreserveWhitespaces>
export class CheckboxDemo &#123;

    selectedCities: string[] = [];

    selectedCategories: any[] = ['Technology', 'Sports'];

    categories: any[] = [&#123;name: 'Accounting', key: 'A'&#125;, &#123;name: 'Marketing', key: 'M'&#125;, &#123;name: 'Production', key: 'P'&#125;, &#123;name: 'Research', key: 'R'&#125;];

    checked: boolean = false;

    ngOnInit() &#123;
        this.selectedCategories = this.categories.slice(1,3);
    &#125;
&#125;
</app-code>
        </p-tabPanel>
        <p-tabPanel header="StackBlitz">
            <ng-template pTemplate="content">
                <iframe src="https://stackblitz.com/edit/primeng-checkbox-demo?embed=1" style="width: 100%; height: 768px; border: none;"></iframe>
            </ng-template>
        </p-tabPanel>
    </p-tabView>
</div>
